package com.wf.day_0606.test3;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author mpk
 * @since 2024/6/6 18:51:46
 */
public class Demo {
    public static void main(String[] args) {


        String path = "src/com/wf/day_0606/A.txt";
        changTxt(path);


    }

    private static void changTxt(String path ) {
        List<String> txt = new ArrayList<>();

        //读文件
        try (BufferedReader br = new BufferedReader(new FileReader(path));) {

            String s;

            while ((s = br.readLine()) != null) {
                txt.add(s);
            }
            String[] chineseNumbers = {"一", "二", "三", "四", "五", "六", "七", "八", "九"};
            txt = txt.stream()
                    .sorted(Comparator.comparing(s1 -> {
                        // 获取字符串在大写中文数字数组中的索引，作为排序依据
                        return Arrays.asList(chineseNumbers).indexOf(s1.substring(0, 1));
                    }))
                    .collect(Collectors.toList());


        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        //写文件

        try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) {

            for (String string : txt) {

                bw.write(string);
                bw.newLine();

            }
            bw.flush();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }


}
